package com.efei.jdbc.sql;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SqlCondition {

    private  String       column;
    private  String       operator;
    private  Object value;
    private  String alis; // 占位符号


    SqlCondition(){
        super();
    }

    public static SqlCondition of(String column, String operator, Object value) {
        SqlCondition sc =new SqlCondition();
        sc.column = column;
        sc.operator = operator;
        sc.value = value;
        sc.setAlis(column);
        return sc;
    }

    public static SqlCondition of(String column, String operator, Object value,String alis) {
        SqlCondition sc =new SqlCondition();
        sc.column = column;
        sc.operator = operator;
        sc.value = value;
        sc.alis=alis;
        return sc;
    }

    public static SqlCondition of(String column, Object value) {
        SqlCondition sc =new SqlCondition();
        sc.column = column;
        sc.operator = "=";
        sc.value = value;
        sc.setAlis(column);
        return sc;
    }

    public static SqlCondition of(String column, Object value,String alis) {
        SqlCondition sc =new SqlCondition();
        sc.column = column;
        sc.operator = "=";
        sc.value = value;
        sc.alis=alis;
        return sc;
    }
    public void setAlis(String alis) {
        if(alis.indexOf(".")>-1) {
            this.alis = alis.replace(".", "_");
        } else {
            this.alis = alis;
        }
    }
}
